package com.joysuch.wwyt.workflow.enums;

/**
 * @Author ZhaoQiuWei
 * @Date 2021/5/17 9:05
 */
public enum WorkFlowCodeStrategyEnum {
    ALWAYS(0, "一直递增"),
    DAY(1, "每天从1递增"),
    MONTH(2, "每月从1递增"),
    YEAR(3, "每年从1递增");

    private Integer index;
    private String value;

    private WorkFlowCodeStrategyEnum(Integer index, String value) {
        this.index = index;
        this.value = value;
    }

    public Integer getIndex() {
        return index;
    }

    public String getValue() {
        return value;
    }

    public boolean is(Integer index) {
        return index != null && this.index.equals(index);
    }

    public static WorkFlowCodeStrategyEnum findByIndex(Integer index) {
        if (index == null) {
            return null;
        }
        for (WorkFlowCodeStrategyEnum strategyEnum : WorkFlowCodeStrategyEnum.values()) {
            if (strategyEnum.index.equals(index)) {
                return strategyEnum;
            }
        }
        return null;
    }

    public static String findValueByIndex(Integer index) {
        WorkFlowCodeStrategyEnum strategyEnum = findByIndex(index);
        return strategyEnum == null ? null : strategyEnum.getValue();
    }
}
